/**
 * 
 */
package bitManipulation;

/**
 * @author michael
 *
 */
public class NumberOfOneBits {

    public int hammingWeight(int n) {
        int result = 0;
    	while (n != 0) {
        	result++;
        	n = n & (n - 1);
        }
        return result;
    }

    public int hammingWeight1(int n) {
        int result = 0;
        while (n != 0) {
            if ((n & 1) == 1) {
                result++;
            }
            n >>>= 1;
        }
        return result;
    }   
    
	/**
	 * 
	 */
	public NumberOfOneBits() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
//		long n = 2147483648;
		int n =  -3;
		NumberOfOneBits instance = new NumberOfOneBits();
		int result = instance.hammingWeight(n);
		System.out.println(result);
	}
}
